/**
 * LayerManager
 * 层级管理类
 * @author jtianling
 */

enum LayerType {
    NORMAL,
    POPUP,
    TIP,
    EFFECT,
    TOPBOTTOM,
    GUIDE,
}
enum CleanType {
    NONE,
    LAST,
    ALL
}
enum BackLayerType {
    SCALE,
    NONE,
}
class LayerManager {

    private static _instance: LayerManager;
    private _guiLayer: GuiLayer;

    public static get instance(): LayerManager {
        if (!LayerManager._instance) {
            LayerManager._instance = new LayerManager();

        }
        return LayerManager._instance;
    }

    /**
     * 切换背景摄像机的背景图
     * @param res 背景图的Res文件名称
     */
    changeBackToGameBackCam(res: string, type: BackLayerType = BackLayerType.SCALE) {
        if (RES.getRes(res)) {
            if (!SceneManager.instance.uiBackRoot) {
                Logger.error("节点未创建");
                return;
            }
            let _node = SceneManager.instance.uiBackRoot.getComponent(egret3d.Egret2DRenderer).root;
            let _image = _node.getChildByName("bg") as eui.UIComponent;
            let _texture = RES.getRes(res) as egret.Texture;
            if (_image && _image instanceof eui.Image) {
                _image.source = res;
            }
            else {
                _image = new eui.Image(res);
                _image.name = "bg";
                _node.addChild(_image);
            }
            _image.x = GameUtils.getSceneWidth() / 2;
            _image.y = GameUtils.getSceneHeigth() / 2;
            if (type == BackLayerType.NONE) {
                _image.anchorOffsetX = _texture.textureWidth / 2;
                _image.anchorOffsetY = _texture.textureHeight / 2;
                _image.width = _texture.textureWidth;
                _image.height = _texture.textureHeight;
            }
            else {
                _image.anchorOffsetX = GameUtils.getSceneWidth() / 2;
                _image.anchorOffsetY = GameUtils.getSceneHeigth() / 2;
                _image.width = GameUtils.getSceneWidth();
                _image.height = GameUtils.getSceneHeigth();
            }
        }
        else {
            Logger.error(res + ":此资源未加载,请加载后尝试");
        }
    }
}
